<?php
class Model_Notice
{
    static private $_table = 'notice';
    static private $_id = 1;
    public static function add($content)
    {
        $content = Model_Common::filterText($content);
        $fields  = array(
        'content'       => $content,
        'modifytime'    => Model_Common::getNowTime()
        );
        $DB = Eren_Registry::get('DB');
        $id = $DB->table(self::$_table)
                 ->insert($fields);
        Model_Log::write("[notice add:{$content}");
        return $id;
    }
    
 	public static function modify($content)
    {        
        $content = Model_Common::filterText($content);
        $fields  = array(
        'content'       => $content,
        'modifytime'    => Model_Common::getNowTime()
        );
        $DB  = Eren_Registry::get('DB');
        $ret = $DB->table(self::$_table)
                  ->where('noticeid', '=', self::$_id)
                  ->update($fields);
        Model_Log::write("[notice update:{$content}");
        return TRUE;
    }
    
    public static function get()
    {
        $DB  = Eren_Registry::get('DB');
        $ret = $DB->table(self::$_table)
                  ->where('noticeid', '=', self::$_id)
                  ->select();
        if($ret['count'] ==0 ) return '';
        return $ret['data'][0]['content'];
    }
}